<?php

namespace app\api\controller;

use ba\Date;
use Throwable;
use ba\Captcha;
use ba\Random;
use app\common\model\User;
use think\facade\Validate;
use app\common\facade\Token;
use app\common\model\UserScoreLog;
use app\common\model\UserMoneyLog;
use app\common\controller\Frontend;
use app\api\validate\Account as AccountValidate;

class Activity extends Frontend
{
    protected array $noNeedLogin = ['lists','details'];


    public function initialize(): void
    {
        parent::initialize();
    }

    public function lists(): void
    {
        $params = $this->request->param();
        $res = \app\admin\model\Activity::where(['status' => 1])->order('weigh asc')->paginate($params['limit'] ?? 10);

        foreach ($res->items() as &$item) {
            $item->cover = full_url($item->cover);
            $item->create_time_text = date('Y-m-d', $item->create_time);
        }

        $this->success('',['lists' => $res->items(),'total' => $res->total()]);
    }

    /**
     */
    public function details(): void
    {

        $params = $this->request->param();
        if (empty($params['id'])) {
            $this->error('活动丢失');
        }
        $row = \app\admin\model\Activity::find($params['id']);
        $this->success('',['row' => $row]);
    }


}
